﻿Imports Entities
Public Class DetalleVentaDAL
    Public Shared Function Create(ByVal zObject As DETALLEVENTA) As DETALLEVENTA
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.DETALLEVENTA.Add(zObject)
                bd.SaveChanges()
                Return zObject
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function DeleteDetalle(ByVal zVentaId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.DETALLEVENTA
                           Where rec.VENTA = zVentaId
                           Select rec).ToList
                For Each r In query
                    bd.DETALLEVENTA.Remove(r)
                Next
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function ListByVentaIdId(ByVal zId As Long) As List(Of DETALLEVENTA)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.detalleventa
                          Where rec.VENTA = zId
                          Select rec).ToList
                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function ListByVentaDistribuidorId(ByVal zId As Long) As List(Of detalleventa)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.detalleventa
                          Where rec.VENTADISTRIBUIDOR = zId
                          Select rec).ToList
                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class
